﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace darkeggs
{
    class laser
    {
        Texture2D TEXTURE;
        string color;
        Vector2 start;
        Vector2 end;
        Vector2 current;

        Vector2 dimensions;

        int range;
        float c;
        float m;
        bool isActive;

        public laser(Texture2D texture,Vector2 startAug, Vector2 endAug, string colorAug, int rangeAug)
        {
            TEXTURE = texture;
            start = startAug;
            end = endAug;
            color = colorAug;
            range = rangeAug;
            //y1- [(y1-y2/x1-x2) * x1] = c
            c = start.Y - ((end.Y- start.Y) / ( end.X-start.X)) * start.X;
            m = (end.Y - start.Y) / ( end.X -start.X);
            current = start;
            isActive = true;

            dimensions = new Vector2(12, 12);
        }

        public void update()
        {

            current.Y = m*(current.X) + c;
            if (end.X - start.X > 0)
                current.X += 1;
            else
                current.X -= 1;
            range--;

            if (range <= 0)
                isActive = false;
        }


        public void draw(SpriteBatch sb)
        {
            Vector2 temp = new Vector2(current.X - (dimensions.X / 2), current.Y - (dimensions.Y / 2));
            sb.Draw(TEXTURE,temp,Color.White);
        }

        public bool isAlive()
        {
            return isActive;
        }

        public Vector2 getPos()
        {
            return current;
        }

    }
}
